package net.bblot.lottery.api.request;

import android.content.Context;
import android.os.Handler;
import android.support.annotation.NonNull;

import net.bblot.lottery.PackegeConfig;
import net.bblot.lottery.api.ApiClinet;
import net.bblot.lottery.api.SimpleResponseListener;
import net.bblot.lottery.api.result.ExcuterResult;
import net.bblot.lottery.api.task.HttpTask;
import net.bblot.lottery.util.AppConfig;
import net.bblot.lottery.util.AppUtil;
import net.bblot.lottery.util.WifiUtil;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by feng on 2017/11/2.
 */

public class Static {
    public static final String TAG = "Static";
    /**
     * 统计新增
     *
     * @param context
     */
    public static void init(Context context) {
        String url = PackegeConfig.Base_url + "/api?m=system.AppInfo.initApp";
        List<NameValuePair> pairs = new ArrayList<>();
        pairs.add(new BasicNameValuePair("channel_number", AppConfig.getAppMetaData(context, "STATION_ID")));
        pairs.add(new BasicNameValuePair("imei", AppUtil.getImei(context)));
        pairs.add(new BasicNameValuePair("mac", WifiUtil.getWifiMac(context)));
        pairs.add(new BasicNameValuePair("packageName", context.getPackageName()));
        pairs.add(new BasicNameValuePair("appVersion", AppConfig.getCurrentAppVersion(context)));
        pairs.add(new BasicNameValuePair("appKey", PackegeConfig.App_key));
        SimpleResponseListener listener = new SimpleResponseListener() {
            @Override
            public void onGetResult(String responsCode, @NonNull ExcuterResult er) {
                String result = er.getResult();
                // Log.e(TAG, "result:" + result);
            }
        };
        final Handler handler = HttpTask.getHttpHandler(listener);
        HttpTask task = HttpTask.getTask(handler, context, url, HttpTask.HTTP_REQEST_TYPE_GET, pairs, null, null, null);
        ApiClinet.getInstance().doHttpTask(task, listener);
    }

}


